<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>考核记录</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="/worker_assets/css/bootstrap.min.css" rel="stylesheet">
	<link href="/worker_assets/css/style.css" rel="stylesheet">
	<link href="/worker_assets/css/font-awesome.css" rel="stylesheet">
    <link rel="stylesheet" href="/plugins/SweetAlert/sweetalert.css" />
</head>
<body>
	<div class="container-fluid">
		<div class="om-ctl-mes">
			<div class="title">
				<div class="col-xs-12"><span class="fa fa-list-ul"> 员工管理</span><b class="fa fa-caret-right"></b><i>考核记录</i></div>
			</div>
            <div class="cent">
    <span class="bg" style="position: absolute;width: 100%;height: 100%;background: black;
    opacity: 0.3;z-index: 10;padding: 0;display: none"></span>
            <div class="modal fade" id="modal_box" tabindex="-1" role="dialog" aria-labelledby="modal_delLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content" style="width:7.50rem;">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">新增</h4>
                            </div>
                            <div class="modal-body" style="width:7.50rem;">
                                <form method="post" class="addTrain">
                                <span>所在部门：</span><select name="department"><option value="0">请选择</option><?php foreach($tDDatas as $tDRow){?><option value="<?=$tDRow['num']?>"><?=$tDRow['introduce']?></option><?php }?></select>
                                <span class="supportworker_name" style="margin-left:.50rem;">员工姓名：</span><select name="supportworker"><option value="0">请选择</option></select><br>
                                <div class="space" style="margin-top:.10rem;"></div>
                                <span>原因：</span></br>
                                <div class="space" style="margin-top:.10rem;"></div>
                                <textarea name="description" value="" style="margin-left:.54rem;width:4.50rem;"></textarea></br>
                                <div class="space" style="margin-top:.10rem;"></div>
                                <span>加分/减分：</span></br>
                                <select name="status" style="margin-left:.54rem;">
                                    <option value="1">+</option>
                                    <option value="2">-</option>
                                </select>
                                <input type="number" name="score" min="0" placeholder="输入分数"/>
                                <div class="space" style="margin-top:.10rem;"></div>
                            </div>
                            <div class="modal-footer">
                                <button class="btn btn-danger btn-sm ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button" aria-disabled="false" onclick="addUser()">
                                    <span class="ui-button-text">
                                        <i class="icon-ok bigger-110"></i>
                                        确 定
                                    </span>
                                </button>
                                <button class="btn btn-sm ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button" aria-disabled="false" data-dismiss="modal">
                                    <span class="ui-button-text">
                                        <i class="icon-remove bigger-110"></i>
                                        取 消
                                    </span>
                                </button>
                            </div>
                            </form>
                        </div>
                    </div>
                </div>
            <div class="modal fade" id="modal_box1" tabindex="-1" role="dialog" aria-labelledby="modal_delLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content" style="width:7.50rem;">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">编辑</h4>
                            </div>
                            <div class="modal-body" style="width:7.50rem;">
                                <form method="post" class="editTrain" action="/admin_train/edit">
                                <span>所在部门：</span>
                                <select name="department" name="department" class="department">
                                    <option value="0">请选择</option>
                                    <?php foreach($tDDatas as $tDRow){?>
                                    <option value="<?=$tDRow['num']?>"><?=$tDRow['introduce']?></option>
                                    <?php }?>
                                </select>
                                <span class="supportworker_name" style="margin-left:.50rem;">员工姓名：</span>
                                <select name="supportworker">
                                <option value="0">请选择</option>
                                </select><br>
                                <div class="space" style="margin-top:.10rem;"></div>
                                <span>原因：</span></br>
                                <div class="space" style="margin-top:.10rem;"></div>
                                <textarea name="description" value="" class="description" style="margin-left:.54rem;width:4.50rem;"></textarea></br>
                                <div class="space" style="margin-top:10px;"></div>
                                <span>加分/减分：</span></br>
                                <select name="status" style="margin-left:.54rem;" class="status">
                                    <option value="1">+</option>
                                    <option value="2">-</option>
                                </select>
                                <input type="number" name="score" min="0" placeholder="输入分数" class="score"/>
                                <div class="space" style="margin-top:.10rem;"></div>
                            </div>
                            <div class="modal-footer">
                                <button class="editUser btn btn-danger btn-sm ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button" aria-disabled="false">
                                    <span class="ui-button-text">
                                        <i class="icon-ok bigger-110"></i>
                                        确 定
                                    </span>
                                </button>
                                <button class="btn btn-sm ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button" aria-disabled="false" data-dismiss="modal">
                                    <span class="ui-button-text">
                                        <i class="icon-remove bigger-110"></i>
                                        取 消
                                    </span>
                                </button>
                            </div>
                            </form>
                        </div>
                    </div>
                </div>
			<div class="seltemple">
                <form action="/admin_appraise" method="get" class="form">
				<div class="col-xs-12">
                    <div class="col-xs-3 mes-group"><label>部门</label><select name="department"><option value="0">请选择</option><?foreach($tDDatas as $tDRow){?><option value="<?=$tDRow['num']?>" <?if($pDepartment == $tDRow['num']){echo 'selected';}?>><?=$tDRow['introduce']?></option><?}?></select></div>
                    <div class="col-xs-3">
                    <label for="exampleInputName2">操作时间</label>
                    <div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" data-link-field="updated">
                    <input class="form-control" name="created" size="16" id="form-control" id="datetime" onclick="WdatePicker();" value="<?=$pCreated?>" readonly="" placeholder="选择入职日期" type="text" style="width:1rem;background:#fff">
                    </div>
                    <input id="updated" value="" name="updated" type="hidden"><br>
                    </div>			
                    <div class="col-xs-3 mes-search"><label>关键词搜索</label><input type="text" name="keyword" value="<?=$pKeyword?>" placeholder="员工姓名/联系电话"><button id="search">搜索</button></div>
					<div class="col-xs-3 mes-btn"><p id="off-btn">新增记录</p></div>
				</div>

                </form>
			</div>
			<div  class="mes-conttent col-xs-12">
				<table class="table kaohe-table">
	              <thead>
	             	<tr>
			        <th>编号</th>
			        <th>姓名</th>
			        <th>所在部门</th>
			        <th>联系电话</th>
			        <th>事因</th>
			        <th>扣分/加分</th>
			        <th>操作时间</th>
			        <th>添加人员</th>
			        <th>操作</th>
		            </tr>
	              </thead>
	             <tbody>
                    <?foreach($tDatas as $tRow){?>
		           <tr>
                        <td><?=$tRow['id']?></td>
                        <td><?=$tRow['name']?></td>
                        
                        <td><?=$tRow['department']?></td>
                        <td><?=$tRow['phone']?></td>
                        <td><?=$tRow['description']?></td>
                        <td><?=$tRow['status'] == 1?'+':'-'?><?=$tRow['score']?></td>
                        <td><?=date('Y-m-d H:i',$tRow['created'])?></td>
                        <td><?=$tRow['user']?></td>
			         <td>
                     <button data="<?=$tRow['id']?>" class="edit">编辑</button>
                     <button onclick="cg_confirm_del('/admin_appraise/delete?id=<?=$tRow['id']?>','/admin_appraise')">删除</button>
			         </td>
		           </tr>
                    <?}?>
	            </tbody>
              </table>
                <?=$tShow?>
			</div>
		</div>
    </div>
    <script type="text/javascript" src="/worker_assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="/worker_assets/js/jq.js"></script>
<script type="text/javascript" src="/plugins/datepicker/WdatePicker.js" charset="UTF-8"></script>
<script src="/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="/plugins/SweetAlert/sweetalert.min.js"></script><!--alert插件-->
    <!-- <script type="text/javascript" src="/worker_assets/js/kaohe-alert.js"></script> -->
<script src="/js/sweetalert-dev.js"></script>
<script>
$(function(){
    var offalert="<div class='off-alert'></div>",
        html = "<div class='mark kaohe-mark'></div>"
               +"<div class='off-alert kaohe-alert'>"
                  +"<h3>新增记录<span class='close1'>×</span></h3>"
                  +"<div class='sle'><label>部门</label><select name='department'><option value='0'>请选择</option><?php foreach($tDDatas as $tDRow){?><option value='<?=$tDRow['num']?>'><?=$tDRow['introduce']?></option><?php }?></select><label>姓名</label><select name='supportworker'><option value='0'>请选择</option></select></div>"
                  +"<div class='col-xs-12'><div class='col-xs-4'>培训内容</div><div class='col-xs-8'><textarea name='description'></textarea></div></div>"
                  +"<div class='kaohe-rad'><input type='radio' name='status' value='1'> 加分<input type='radio' name='status' value='2'> 减分<input type='text' placeholder='输入分数' name='score' ></div>"
          +"<div class='btns'><button type='button' onclick='addUser()'>保存</button><button type='button' class='close1'>取消</button></div>"
          +"</div>";
       $("body").prepend($(html))
    $(".mark").css("height",$(document).height()+"px")      
   $(".mark").addClass('hidden')    
   $(".off-alert").addClass('hidden')
      $("#off-btn").click(function(){
           $('.mark').show()
           $('.off-alert').show()
           $(".off-alert").removeClass('hidden')
           $(".mark").removeClass('hidden')
       
     })
    $(".close1").click(function(){
           $('.mark').hide()
           $('.off-alert').hide()
           $(".off-alert").addClass('hidden')
           $(".mark").addClass('hidden')
     })
})
$('#search').click(function(){
    $('.form').submit();
});
/*获取地址栏参数*/
function GetQuery(key){
	var search = location.search.slice(1);//得到get方式提交的查询字符串
	var arr = search.split("&");
	for(var i = 0; i < arr.length; i++){
		var ar = arr[i].split("=");
		if(ar[0] == key){
			return ar[1];
		}
	}
}
$('select[name="department"]').change(function(){
    var department_id = $(this).val();
    $.post('/admin_appraise',{department_id:department_id},function(obj){
        $('select[name="supportworker"]').remove();
        if(obj.status == 1){
            var data = obj.data;
            var html = (
                '<select name="supportworker">'
            );
            $.each(data,function(key,row){
                html += '<option value="'+row.id+'">'+row.name+'</option>';
            }); 
            html += '</select>';
            html += '<input type="hidden" name="tId" value="" class="tId"/>'
            $('.supportworker_name').append(html);
        }
    });
});
function sel(data){
    $('select[name="supportworker"]').remove();
    var html = (
        '<select name="supportworker">'
    );
    html += '<option value="'+data.w_id+'">'+data.name+'</option>';
    html += '</select>';
    $('.supportworker_name').append(html);
}
function editTrain(){
    $('#modal_box1').modal('toggle');
    var t_id = $(this).attr('data');
    alert(t_id);
}
var tId = '';
$('.edit').each(function(){
    $(this).click(function(){
        $('#modal_box1').modal('toggle');
        var t_id = $(this).attr('data');
        $.get('/admin_appraise',{t_id:t_id},function(obj){
            if(obj.status == 1){
                var data = obj.data;
                $('select[class="department"]').val(data.department);
                //$('select[class="supportworker"]').val(data.w_id);
                sel(data);
                $('textarea[class="description"]').val(data.description);
                $('select[class="status"]').val(data.status);
                $('input[class="score"]').val(data.score);
                tId = data.id;
            }    
        });
        $('.editUser').click(function(){
            var edit_data = $('form[class="editTrain"]').serialize();
            edit_data += '&tId='+tId;
            $.post('/admin_appraise/edit',edit_data,function(obj){alert(obj.msg);location.href="/admin_appraise";});
        });
    });
});
function addUser(){
    var data = $('.addTrain').serialize();
    $.post('/admin_appraise/add',data,function(obj){
        if(obj.status == 1){
            alert(obj.msg);location.href="/admin_appraise";
        }
        alert(obj.msg);return;
    });
}
    var color="#eeeeee";
    $("#table_list tr:odd td").css("background-color",color);  //改变偶数行背景色
    /* 把背景色保存到属性中 */
    $("#table_list tr:odd").attr("bg",color);
function cg_confirm_del(del_url,jump_url){
    swal({
            title: '您确定要删除吗？',
            text:'删除之后不能恢复',
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText:'确定',
            closeOnConfirm: false,
            cancelButtonText:'取消'
        },
        function(isConfirm){
            if(isConfirm){
                window.obj = '';
                $.ajax({
                    url: del_url,
                    dataType: "json",
                    async:false,
                    success: function (obj) {
                        window.obj = obj;
                    }
                });

                if(window.obj.status == 1){
                    swal({title:"删除成功!", type:"success"},function(){
                        location.href = jump_url;
                    });
                }else{
                    swal({title:window.obj.msg, type:"error"});
                }
            }
        });
}
</script>
</body>
</html>
